<template>
  <div id="plan_all">
    <div class="search">
      <el-form :inline="true" :model="search" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input
            v-model="search.key"
            placeholder="请输入设备名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="输入时间">
          <el-date-picker
            v-model="search.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="chage"
          ></el-date-picker>
        </el-form-item>
        <el-form-item
        >
          <el-button type="primary" @click="onsubmit"
          >查询
          </el-button
          >
        </el-form-item
        >
      </el-form>
      <el-button class="ebtn" type="warning" @click="addorder(null,null)"
      >销售计划
      </el-button
      >
    </div>
    <div class="order_table">
      <template>
        <el-table :data="ListData" style=" margin: 10px 20px;width: calc(100% - 40px)"  :height="autoHeightTable" stripe>
          <!-- <el-table-column prop="xuhao" label="序号" align="center"></el-table-column> -->
          <el-table-column
            label="序号"
            align="center"
          >
            <template slot-scope="scope">
              <span>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="createonTime"
            label="日期"
            align="center"
          >
            <template v-slot="scope">
              <span>
                {{formatTime(scope.row.createonTime)}}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            prop="createonUsername"
            label="业务员"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="clientName"
            label="对应主机厂"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="status"
            label="状态"
            align="center"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.status==1">待审核</span>
              <span v-if="scope.row.status==2">已完成</span>
              <el-button v-if="scope.row.status == 3" type="text" size="medium"
                         @click="dialogVisible_bohui = true,getReject(scope.row)">驳回
              </el-button>
<!--              <span v-if="scope.row.status==3">驳回</span>-->
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="200">
            <el-row slot-scope="scope">
              <!-- <el-button
                size="mini"
                type="warning"
                v-if="scope.row.state == '待下发'"
                @click="daixiafa(scope.row.planno)"
                >下发</el-button
              > -->
              <el-button
                size="mini"
                type="primary"
                v-if="scope.row.status==1"
                @click="sh(scope.row.id, null)"
                >审核</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="sh(scope.row.id, 1)"
                >详情</el-button
              >
            </el-row>
          </el-table-column>
        </el-table>
      </template>
      <el-pagination
        background
        layout="prev, pager, next"
        :current-page="current"
        :page-size="pagesize"
        @current-change="handleCurrentChange"
        :page-count="total"
      >
      </el-pagination>
      <el-dialog
        title="驳回详情"
        :visible.sync="dialogVisible_bohui"
        width="50%"
        :modal-append-to-body="false">
        <ul :data="reject" class="bohuizujian">
          <li>
            <span>审核日期</span>
            <el-input v-model="reject.checkTime" style="width: 70%;" disabled></el-input>
          </li>
          <li>
            <span>驳回理由</span>
            <el-input v-model="reject.bohui" style="width: 70%;" disabled></el-input>
          </li>
        </ul>

        <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="dialogVisible_bohui = false">返 回</el-button>
  </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      search: { key: "", start: "", end: "" },
      ListData: [],
      total: 1,
      current: 1,
      pagesize: 10,
      dialogVisible_bohui: false,
      reject: {
        checkTime:"",
        bohui:"",
      },
    };
  },
  computed: {
    autoHeightTable() {
      return document.documentElement.scrollHeight - 251 - 78;
    },
  },
  created() {
    this.getList(0);
  },
  methods: {
    getReject(row) {
      this.reject = row
      this.reject.checkTime = this.formatTime(row.checkTime)
      console.log(this.reject)
    },
    //时间格式化
    formatTime(data){
      return data==null?"":data.substring(0, 10);
    },
    getList() {
      const json = {
        beginTime: this.search.start,
        endTime: this.search.end,
        key: this.search.key,
        pageNum: this.current,
        pageSize: this.pagesize,
      };
      const message = JSON.parse(localStorage.getItem("message"));
      axios
        .post(
          "/JX_java/sales/orderFrom/getSaleOrderPlanList?userId=" + message.Id,
          json
        )
        .then((res) => {
          this.ListData = res.data.data.content;
          this.total= res.data.data.totalPages
          for (let i = 0; i < this.ListData.length; i++) {
            this.ListData[i].createonTime = this.ListData[i].createonTime.substring(0, 10)
          }

        });
    },

    handleCurrentChange(e) {
      this.current = e;
      this.getList();
    },

    onsubmit() {
      this.getList();
    },

    chage(e) {
      if (e) {
        this.search.start = e[0];
        this.search.end = e[1];
      } else {
        this.search.start = "";
        this.search.end = "";
      }
    },
    // 订单审核
    sh(id, e) {
      this.$router.push({
        path: "/PlanManageSh",
        query: { id: id, edit: e },
      });
    },
    //新增订单计划
    addorder() {
      this.$router.push("/PlanManageAdd");
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/base.scss";
#plan_all .search {
  height: 50px;
  border-radius: 5px;
  background-color: #fff;
  padding-left: 20px;
  padding-top: 10px;
   margin: 0 20px ;
  //margin-bottom: 10px;
}

#plan_all .demo-form-inline {
  display: inline-block;
}

#plan_all .el-pagination {
  margin-top: 15px;
  text-align: center;
}

#plan_all .ebtn {
  float: right;
  margin-right: 20px;
}
.bohuizujian {
  display: flex;
  flex-wrap: wrap;

  li {
    width: 50%;
    padding-top: 10px;
    text-align: center;

    span {
      display: inline-block;
      width: 25%;
    }

  }
}
</style>
<style>
.el-dialog__footer {
  text-align: center;
}
#plan_all .el-dialog__body {
  padding-top: 0;
}
</style>
